package com.mathew.spring.appsp.conf;

import java.util.Timer;
import java.util.TimerTask;

import com.rabbitmq.client.Channel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MQReceiver {
  private static final Logger logger = LoggerFactory.getLogger(MQReceiver.class);

  @RabbitListener(queues = "node_queue")
  public String process(String msg, Message data, Channel channel) {
    logger.info("node_queue" + data.toString());
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
      public void run() {
        logger.info(data.toString());
      }
    }, 2 * 1000);
    return "接受到消息:" + data.getMessageProperties().getConsumerTag();
  }
}
